#
# @lc app=leetcode.cn id=121 lang=python
#
# [121] 买卖股票的最佳时机
#

# @lc code=start
class Solution(object):
    def maxProfit(self, prices):
        """
        :type prices: List[int]
        :rtype: int
        """
        # 0:买, 1:卖
        dp = [0]*2
        dp[0] = prices[0]
        dp[1] = 0
        for i in range(1, len(prices)):
            dp[1] = max(dp[1], prices[i]-dp[0])
            dp[0] = min(dp[0], prices[i])
        return dp[1]
            
        
# @lc code=end

